package com.aaa.appUtil.util;

import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * fileName:InterceptorUtilImpl
 * description:
 * author:zxh
 * createTime:2020/1/10 15:07
 * version:1.0.0
 */
public class InterceptorUtilImpl extends InterceptorUtil {
    /**
     * 在请求处理前调用（controller方法调用前）
     * @param request
     * @param response
     * @param handler
     * @return
     * @throws Exception
     */
    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
        //此处暂时写成这样
        try {
            Object user = request.getSession().getAttribute("user");
            if (user!=null){
                return true;
            }
            response.sendRedirect(request.getContextPath()+"此处为登陆页面地址");
        } catch (IOException e) {
            e.printStackTrace();
        }
        return false;
    }

    @Override
    public void postHandle(HttpServletRequest request, HttpServletResponse response, Object handler, ModelAndView modelAndView) throws Exception {

    }

    @Override
    public void afterCompletion(HttpServletRequest request, HttpServletResponse response, Object handler, Exception ex) throws Exception {

    }
}
